package com.scau402.system1.mapper;

import com.github.yulichang.base.MPJBaseMapper;
import com.scau402.system1.domain.po.WmsWarehouseStoragePO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * 仓库仓位Mapper接口
 *
 * @author ruoyi
 * @date 2023-06-26
 */
public interface WmsWarehouseStorageMapper extends MPJBaseMapper<WmsWarehouseStoragePO> {
    /**
     * 根据id获取仓位名称
     * @param id 仓位id
     * @return
     */
    @Select("select storage_name from wms_warehouse_storage where id = #{id}")
    String selectNameById(@Param("id") Long id);
    /**
     * 查询已用容量
     * @param id 仓位id
     * @return
     */
    @Select("select used_cap from wms_warehouse_storage where id = #{id};")
    Long selectUCById(@Param("id") Long id);

    /**
     * 查询属下仓位ids
     * @param rootStorageId 根仓位id
     * @return ids
     */
    @Select("select id from wms_warehouse_storage where parent_storage = #{rootStorageId}")
    List<Long> selectChildStorageIdById(@Param("rootStorageId") Long rootStorageId);
    /**
     * 查询仓库仓位
     *
     * @param id 仓库仓位主键
     * @return 仓库仓位
     */
    public WmsWarehouseStoragePO selectWmsWarehouseStorageById(Long id);

    /**
     * 查询仓库仓位列表
     *
     * @param wmsWarehouseStoragePO 仓库仓位
     * @return 仓库仓位集合
     */
    public List<WmsWarehouseStoragePO> selectWmsWarehouseStorageList(WmsWarehouseStoragePO wmsWarehouseStoragePO);

    /**
     * 新增仓库仓位
     *
     * @param wmsWarehouseStoragePO 仓库仓位
     * @return 结果
     */
    public int insertWmsWarehouseStorage(WmsWarehouseStoragePO wmsWarehouseStoragePO);

    /**
     * 修改仓库仓位
     *
     * @param wmsWarehouseStoragePO 仓库仓位
     * @return 结果
     */
    public int updateWmsWarehouseStorage(WmsWarehouseStoragePO wmsWarehouseStoragePO);

    /**
     * 删除仓库仓位
     *
     * @param id 仓库仓位主键
     * @return 结果
     */
    public int deleteWmsWarehouseStorageById(Long id);

    /**
     * 批量删除仓库仓位
     *
     * @param ids 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteWmsWarehouseStorageByIds(Long[] ids);

    public String getMaxCode(Long tenantId);

    public void deleteWmsWarehouseStorageParentWarehouseId(Long id);

    int checkCodeUnique(WmsWarehouseStoragePO wmsWarehouseStoragePO);

    void updateInventory(@Param("jadeQuantity") Long jadeQuantity, @Param("storageId") Long storageId);

    @Select("select data_version from wms_warehouse_storage where id = #{storageId}")
    Long selectVersionById(@Param("storageId") Long storageId);

    @Update("update wms_warehouse_storage " +
            "set used_cap = used_cap + #{jadeQuantity} " +
            "where id = #{storageId}")
    void addInventory(@Param("storageId") Long storageId,@Param("jadeQuantity") Long jadeQuantity);

    @Select("select used_cap,max_cap from wms_warehouse_storage where id = #{storageId}")
    WmsWarehouseStoragePO selectCapById(@Param("storageId") Long storageId);
}
